/*
 * SN76489_regs.hpp
 *
 *  Created on: Jan 1, 2012
 *      Author: douglas
 */

struct reg10_t
{
	union
	{
		uint16 hex;

		struct
		{
			uint16            : 6;
			uint16 high6bits  : 6;
			uint16 low4bits   : 4;
		};
	};

	inline operator unsigned() const { return hex; }
	inline unsigned operator   = (unsigned i) { return hex = uclip<10>(i); }
	inline unsigned operator  |= (unsigned i) { return hex = uclip<10>(hex  | i); }
	inline unsigned operator  ^= (unsigned i) { return hex = uclip<10>(hex  ^ i); }
	inline unsigned operator  &= (unsigned i) { return hex = uclip<10>(hex  & i); }
	inline unsigned operator <<= (unsigned i) { return hex = uclip<10>(hex << i); }
	inline unsigned operator >>= (unsigned i) { return hex = uclip<10>(hex >> i); }
	inline unsigned operator  += (unsigned i) { return hex = uclip<10>(hex  + i); }
	inline unsigned operator  -= (unsigned i) { return hex = uclip<10>(hex  - i); }
	inline unsigned operator  *= (unsigned i) { return hex = uclip<10>(hex  * i); }
	inline unsigned operator  /= (unsigned i) { return hex = uclip<10>(hex  / i); }
	inline unsigned operator  %= (unsigned i) { return hex = uclip<10>(hex  % i); }
};

struct reg4_t
{
	union
	{
		uint8 hex;

		struct
		{
			uint8            : 4;
			uint8 low4bits   : 4;
		};
	};

	inline operator unsigned() const { return hex; }
	inline unsigned operator   = (unsigned i) { return hex = uclip<4>(i); }
	inline unsigned operator  |= (unsigned i) { return hex = uclip<4>(hex  | i); }
	inline unsigned operator  ^= (unsigned i) { return hex = uclip<4>(hex  ^ i); }
	inline unsigned operator  &= (unsigned i) { return hex = uclip<4>(hex  & i); }
	inline unsigned operator <<= (unsigned i) { return hex = uclip<4>(hex << i); }
	inline unsigned operator >>= (unsigned i) { return hex = uclip<4>(hex >> i); }
	inline unsigned operator  += (unsigned i) { return hex = uclip<4>(hex  + i); }
	inline unsigned operator  -= (unsigned i) { return hex = uclip<4>(hex  - i); }
	inline unsigned operator  *= (unsigned i) { return hex = uclip<4>(hex  * i); }
	inline unsigned operator  /= (unsigned i) { return hex = uclip<4>(hex  / i); }
	inline unsigned operator  %= (unsigned i) { return hex = uclip<4>(hex  % i); }
};

struct regs_t
{
	reg10_t rt[4], &reg_tone0, &reg_tone1, &reg_tone2, &reg_tone3;
	reg4_t rvn[4], &reg_vol0, &reg_vol1, &reg_vol2, &reg_noise;
	void * latch;

	regs_t() : 	reg_tone0(rt[0]), reg_tone1(rt[1]), reg_tone2(rt[2]), reg_tone3(rt[3]), reg_vol0(rvn[0]),
				reg_vol1(rvn[1]), reg_vol2(rvn[2]), reg_noise(rvn[3])
	{
		latch = &rt[0];
		reg_tone0 = reg_tone1 = reg_tone2 = reg_tone3 = 0;
		reg_vol0 = reg_vol1 = reg_vol2 = 0xF;
	}


};
